﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Code;
using DB;
using Microsoft.AspNetCore.Mvc;
using Models;

namespace LayuiAdmin.Controllers {
    public class FinanceController : Controller {
        public IActionResult IncomeList(int id) {
            var list = BaseCode.GetEnumByList<SystemType>(new ItemList { text = "请选择", value = 0 });
            ViewData["Id"] = HttpContext.User.Identity.GetValue(ClaimTypes.Sid);
            ViewData["userType"] = HttpContext.User.Identity.GetValue("UserType");
            ViewBag.UserId = id;

            if (id == 0) {
                ViewBag.Title = "收入明细";
            } else {
                using (var context = new SqlServerDB()) {
                    var user = context.Users.FirstOrDefault(m => m.Id == id);

                    ViewBag.Title = $"收入明细 - {user.UserName}";
                }
            }

            return View(list.Where(m => (m.value >= 200 && m.value < 300) || m.value == 0).ToList());
        }

        public IActionResult CashLogList() {
            var list = BaseCode.GetEnumByList<CashStatus>(new ItemList { text = "请选择", value = 0 });
            ViewData["Id"] = HttpContext.User.Identity.GetValue(ClaimTypes.Sid);
            ViewData["userType"] = Convert.ToInt32(HttpContext.User.Identity.GetValue("UserType"));

            return View(list);
        }
    }
}